<?php
// +----------------------------------------------------------------------
// | Longbing [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright Chengdu longbing Technology Co., Ltd.
// +----------------------------------------------------------------------
// | Website http://longbing.org/
// +----------------------------------------------------------------------
// | Sales manager: +86-13558882532 / +86-13330887474
// | Technical support: +86-15680635005
// | After-sale service: +86-17361005938
// +----------------------------------------------------------------------

namespace app\website\model;
use app\BaseModel;
use think\facade\Db;

class CardVideoCategory extends BaseModel{

    //定义表名
    protected $name = 'longbing_card_video_category';

    public $append = ['video_count'];

    /**
     **@param $value
     * @param $data
     * @功能说明: 统计该分类下有多少文件
     * @author lichuanming
     * @DataTime: 2020/5/14 14:55
     */
    public function getVideoCountAttr($value,$data){
        return isset($data['id'])?Db::name('longbing_card_video')->where([
            'category_id'=>$data['id'],
            'status'=>1,
        ])->count():0;
    }

    /**
     **@author lichuanming
     * @DataTime: 2020/5/14 14:23
     * @功能说明: 分类列表
     */
    public function lists($where = [],$page = 0,$list_rows = 0){
        $query = $this->where($where)->order('top desc,create_time desc');
        if($page && $list_rows){
            $query = $query->paginate([ 'list_rows' => $list_rows, 'page' => $page]);
        }else{
            $query = $query->select();
        }
        $list = $query->toArray();
        return $list;
    }


}